<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 微信素材主表
 */
class CreateWxMaterial extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('wx_materials', function (Blueprint $table) {
            $table->increments('material_id')->comment('素材序号');
            $table->string('appid', 64)->default('')->comment('微信应用ID');
            $table->unsignedInteger('cat_id')->default(0)->comment('素材所属分组');
            $table->string('type', 20)->default('')->comment('素菜类别');
            $table->string('title', 200)->default('')->comment('标题');
            $table->mediumText('description')->nullable()->comment('描述');
            $table->string('music_url', 200)->default('')->comment('音乐链接');
            $table->string('hq_music_url', 200)->default('')->comment('高质量音乐链接');
            $table->unsignedInteger('file_id')->default(0)->comment('文件ID，对应sys_files表主键');
            $table->string('view_url',200)->default('')->comment('访问地址');
            $table->string('wx_view_url',250)->default('')->comment('微信端访问地址');
            //音乐素材字段
            $table->unsignedInteger('thumb_material_id')->default(0)->comment('封面图素材主键');
            $table->string('thumb_media_id', 150)->default('')->comment('封面图素材ID');
            $table->string('thumb_view_url', 200)->default('')->comment('封面图访问地址');
            $table->mediumText('preview_data')->nullable()->comment('预览数据');
            $table->unsignedTinyInteger('is_forever')->default(0)->comment('是否为永久素材(0:临时,1:永久)');
            $table->string('media_id', 150)->default('')->comment('素材ID');
            $table->string('mass_media_id', 150)->default('')->comment('群发素材ID');
            $table->timestamp('expire_time')->nullable()->comment('过期时间');
            $table->timestamp('push_time')->nullable()->comment('推送时间');
            $table->string('push_result',100)->default('')->comment('推送返回信息');
            $table->charset = 'utf8';
            $table->collation = 'utf8_unicode_ci';
            $table->softDeletes();
            $table->timestamps();
            $table->index(['view_url','deleted_at'], 'idx_1');
            $table->index(['wx_view_url','deleted_at'], 'idx_2');
            $table->index(['appid','type','updated_at','deleted_at'], 'idx_3');
            $table->index(['appid','media_id','deleted_at'], 'idx_4');
            $table->index(['appid','type'], 'idx_5');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wx_materials');
    }
}
